define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jingang_othergoods/index' + location.search,
                    add_url: 'jingang_othergoods/add',
                    edit_url: 'jingang_othergoods/edit',
                    del_url: 'jingang_othergoods/del',
                    multi_url: 'jingang_othergoods/multi',
                    table: 'jingang_othergoods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {field: 'jingang.name', title: __('Jingang.name'),operate:"LIKE"},
                        {field: 'jingangclass.name', title: __('Jingangclass.name'),operate:"LIKE"},
                        {field: 'goods.name', title: __('Goods.name'),operate:"LIKE"},
                        {field: 'goods.price', title: __('Goods.price'), operate:'BETWEEN'},
                        {field: 'goods.old_price', title: __('Goods.old_price'), operate:'BETWEEN'},
                        {field: 'goods.image', title: __('Goods.image'), events: Table.api.events.image, formatter: Table.api.formatter.image,operate:false},
                        {field: 'goods.status', title: __('状态'), searchList: {"1":__('上架'),"2":__('下架')}, formatter: Table.api.formatter.status},
                        
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});